package com.byref.liteflowdemo.cmp.order;

import com.yomahub.liteflow.core.NodeComponent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * @author BYREF
 */
@Component("calculatePrice")
@Slf4j
public class CalculatePriceCmp extends NodeComponent {
    @Override
    public void process() throws Exception {
        log.info("开始计算价格");
        PriceContext priceContext = this.getContextBean(PriceContext.class);
        OrderContext orderContext = this.getContextBean(OrderContext.class);

        BigDecimal unitPrice = new BigDecimal("100");
        if("iphone".equalsIgnoreCase(orderContext.getProductId())){
            unitPrice = new BigDecimal("200");
        }
        priceContext.setPrice(unitPrice.multiply(new BigDecimal(orderContext.getAmount())));

    }
}
